<?php

defined('SYSPATH') or die('No direct script access.');

class Controller_Work extends Controller {

	public function after() {
		parent::after();
	}

	public function action_index() {
		$a = '';
		$arr = explode("\n", $a);
		$ar2 = array();
		foreach ($arr as $id => &$str) {
			$aa = explode("\t", trim($str));
			if (empty($aa[1])) {
				unset($arr[$id]);
			}
			elseif (!isset($ar2[$aa[1]])) {
				$aa[0] = trim($aa[0]);
				$aa[1] = trim($aa[1]);
				$ar2[$aa[1]] = $aa[0];
				$b[] = $aa[1];

				if (file_exists(DOCROOT . 'i/' . $aa[1] . '.png')) {
					copy(DOCROOT . 'i/' . $aa[1] . '.png', DOCROOT . 'i/' . $aa[0] . '.png');
					echo '.' . $aa[0] . ' {background-image: url(http://img.static.operator.mail.ru/wf/main/content/items/' . $aa[0] . '.png);}' . PHP_EOL;
				}
				else {
					echo 'file: "i/' . $aa[1] . '.png" not found' . PHP_EOL;
				}
			}
			/*
			  if (!empty($ar2[$aa[1]])){
			  $ar2[$aa[1]] = $aa[0];
			  echo $ar2[$aa[1]] .PHP_EOL;
			  }else {
			  $ar2[$aa[1]] = $aa[0];
			  }
			 */
			//$ar2[$aa[1]] = $aa[0];
			//$b[] = $aa[1];
		}
		sort($b);
		print_r($b);
		echo count($arr) . PHP_EOL;
		echo count($ar2) . PHP_EOL;
	}

	public function action_test(){
		$a = '';
		$b = '';

		$aarr = explode("\n",$a);
		$barr = explode("\n",$b);
		foreach ($barr as $str){
			list($csa,$mail) = explode("\t",trim($str));
			echo $csa = trim($csa);
			foreach ($aarr as $str2){
				list($csa2,$nick) = explode(",",trim($str2));
				$csa2  =trim($csa2);
				if ($csa == $csa2){
					$arr[$csa] = trim($nick).','.($mail);
					break;
				}
			}
		}
		echo implode('<br>',$arr);

	}
}

// End Zabbix
